﻿@using Abc.Utils;
@using Abc.Core.Enums
@model Abc.Application.HtAdminServices.HtMenuOut
@{
    ViewData["Title"] = "MenuInfo";
}

<section class="panel panel-padding">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

        <form class="layui-form" action="">
            <input type="hidden" asp-for="Id" />

            <div class="layui-row layui-col-space10">
                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-header">1</div>
                        <div class="layui-card-body">
                            <div class="layui-form-item">
                                <label class="layui-form-label">区域(Area)</label>
                                <div class="layui-input-block">
                                     <input asp-for="Area" lay-verify="area" lay-reqText="Area不能为空！" autocomplete="off" placeholder="请输入Area" class="layui-input">
                                </div>
                                <blockquote class="layui-elem-quote">注意：如果有Area一定要填写area</blockquote>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">上级(PCode)</label>
                                <div class="layui-input-block">
                                    <ul id="PCode" class="dtree" data-id="" data-value="@Model?.PCode"></ul>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">菜单ID</label>
                                <div class="layui-input-block">
                                    <input asp-for="Code" lay-verify="Code" autocomplete="off" placeholder="请输入菜单ID" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">格式 例如：HtAdmin_User</div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">菜单名称</label>
                                <div class="layui-input-block">
                                    <input asp-for="Name" lay-verify="Name" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">格式 例如：用户列表</div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">图标</label>
                                <div class="layui-input-block">
                                    <input asp-for="Icon" lay-filter="iconPicker" class="hide">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">节点类型(菜单、工具栏)</label>
                                <div class="layui-input-block">
                                    <select asp-for="MenuType">
                                        <option value="">--请选择--</option>
                                        @foreach (int val in Enum.GetValues(typeof(MenuType)))
                                        {
                                            if (val == 1 && (Model == null || Model.Id <= 0))
                                            {
                                                <option value="@(val)" selected>@(((MenuType)val).ToString())</option>
                                            }
                                            else
                                            {
                                                <option value="@(val)">@(((MenuType)val).ToString())</option>
                                            }

                                        }
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-header">2</div>
                        <div class="layui-card-body">
                            <div class="layui-form-item">
                                <label class="layui-form-label">Url</label>
                                <div class="layui-input-block">
                                    <textarea asp-for="Url" placeholder="请输入Url" class="layui-textarea"></textarea>
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    @*<i class="layui-icon layui-icon-about" style="font-size: 30px; color: #dddddd;"></i>*@
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">打开方式</label>
                                <div class="layui-input-block">
                                    <select asp-for="OpenType">
                                        <option value="">--请选择--</option>
                                        @foreach (int val in Enum.GetValues(typeof(MenuOpenType)))
                                        {
                                            <option value="@(val)">@(((MenuOpenType)val).ToString())</option>
                                        }
                                    </select>
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    @*<i class="layui-icon layui-icon-about" style="font-size: 30px; color: #dddddd;"></i>*@
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">顺序</label>
                                <div class="layui-input-block">
                                    <input asp-for="Sort" lay-verify="Sort" autocomplete="off" placeholder="请输入顺序" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    @*<i class="layui-icon layui-icon-about" style="font-size: 30px; color: #dddddd;"></i>*@
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" asp-for="IsEnable" lay-skin="primary" title="是否启用" checked>
                                    <input type="checkbox" asp-for="IsShow" title="是否显示" lay-skin="primary" checked>
                                    <input type="checkbox" asp-for="IsExpand" lay-skin="primary" title="是否展开菜单">
                                   
                                   
                                    <input type="checkbox" asp-for="IsDisuse" title="是否作废" lay-skin="primary" disabled>
                                    <input type="checkbox" asp-for="IsSystem" title="是否系统菜单" lay-skin="primary" disabled>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                    <textarea asp-for="Remark" placeholder="请输入备注" class="layui-textarea"></textarea>
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    @*<i class="layui-icon layui-icon-about" style="font-size: 30px; color: #dddddd;"></i>*@
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-btn submitbtn" lay-submit lay-filter="submit">提交数据</div>
                    <div class="layui-btn layui-btn-danger closewindow">关闭窗口</div>
                    <div class="layui-btn layui-btn-danger refreshwindow">重新加载</div>
                </div>
            </div>
        </form>
    </div>
</section>

@*<script src="~/lib/ckeditor4/ckeditor.js"></script>*@
@section Scripts{
    <script>
        layui.define(['element', 'jquery', 'form', 'dtree', 'iconPicker'], function () {
            var $ = layui.jquery;
            var form = layui.form;
            var element = layui.element;
            var dtree = layui.dtree;
            var iconPicker = layui.iconPicker;
            var iconPicker = layui.iconPicker;

             //提交
             form.on('submit(submit)', function (obj) {
                 //obj.field.IsEnable=$('#IsEnable').is(':checked');
                 //obj.field.Remark = Remark.getContent();
                 obj.field.IsEnable=$('#IsEnable').is(':checked');
                 obj.field.IsExpand=$('#IsExpand').is(':checked');
                 obj.field.IsDisuse=$('#IsDisuse').is(':checked');
                 obj.field.IsShow=$('#IsShow').is(':checked');
                 obj.field.IsSystem=$('#IsSystem').is(':checked');

                 obj.field.PCode = dtree.getNowParam("PCode").nodeId;  //获取当前选中节点值
                 abc.post({ url: '@(Url.Action("Edit"))', data: obj.field});

                 return false;
             });

            dtree.renderSelect({
                elem: "#PCode",
                url: "@Url.Action("GetMenuTrees")",
                selectInitVal: "@(Model.PCode)", // 你可以在这里指定默认值
                done: function (res, $ul, first) {
                    if (first) {
                        dtree.dataInit("PCode", "@(Model.PCode)");
                    //    // 也可以在这里指定，第二个参数如果不填，则会自动返显当前选中的数据
                    //    var selectParam = dtree.selectVal("PMId");
                    }

                }
            });

            //icon.render({
            //    elem: '#Icon'
            //    ,style: 'color: #5FB878;'
            //    ,placeholder: ''
            //    ,isSplit: true
            //    ,page: false
            //    ,search: true
            //    ,click: function(obj){
            //    console.log(obj)
            //}
            //,ready: function(){
            //    console.log(1)
            //}});
            iconPicker.render({
                // 选择器，推荐使用input
                elem: '#Icon',
                // 数据类型：fontClass/unicode，推荐使用fontClass
                type: 'fontClass',
                // 是否开启搜索：true/false
                search: true,
                // 是否开启分页
                page: false,
                // 每页显示数量，默认12
                limit: 20,
                // 点击回调
                click: function (data) {
                    console.log(data);
                },
                // 渲染成功后的回调
                success: function (d) {
                    console.log(d);
                }
            });

         });
    </script>
}
